package controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.connector.Request;

import BizLogic.BadDataException;
import BizLogic.LoginCredentialsManager;

import dao.LoginCredentialsDAO;

import dao.mysql.LoginCredentialsDAOImpl;

/**
 * Servlet implementation class LoadManagersServlet
 */
@SuppressWarnings("unused")
@WebServlet("/LoadManagersServlet")
public class LoadManagersServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoadManagersServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		loadManager(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		loadManager(request,response);
	}
	private void loadManager(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
			HttpSession session=request.getSession(true);
			session.setAttribute("StaffID", "A0102936J");
			if(session!=null){
				System.out.println("session entered");
		LoginCredentialsManager managers=new LoginCredentialsManager();
		ArrayList<String> man=new ArrayList<String>();
		try {
			 man=managers.getManagers();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BadDataException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
			boolean insert=true;
			request.setAttribute("insert", insert);
			request.setAttribute("managers", man);
			RequestDispatcher rd=request.getRequestDispatcher("CreateStaff.jsp");
			rd.forward(request,response);
		
	
			}
			else{
				response.sendRedirect("Login.jsp");
			}
	}
}
